import java.util.Scanner;

public class test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        StringBuffer stringBuffer = new StringBuffer(str);
        int i = in.nextInt();
        while (i-- > 0){
            String s = in.nextLine();
            String[] value = s.split(" ");
            if (value[0].equals("1")){
                stringBuffer.delete(Integer.parseInt(value[1])-1,Integer.parseInt(value[2]) - 1);
            }else {
                stringBuffer.insert(Integer.parseInt(value[1]),value[2]);
            }
        }
        System.out.println(stringBuffer);
    }
}
